﻿
namespace UsingNonMVVMElements.ViewModel
{
    using GalaSoft.MvvmLight;
    using GalaSoft.MvvmLight.Command;
    using System;

    public class MainWindowViewModel : ViewModelBase
    {
        #region Public Properties

        string _sourcePage = "http://www.google.com";
        public string SourcePage
        {
            get { return _sourcePage; }
            set
            {
                _sourcePage = value;
                RaisePropertyChanged("SourcePage");
            }
        }

        string _userSuggestedSourcePage = "http://www.google.com";
        public string UserSuggestedSourcePage
        {
            get { return _userSuggestedSourcePage; }
            set
            {
                _userSuggestedSourcePage = value;
                RaisePropertyChanged("UserSuggestedSourcePage");
            }
        }

        #endregion

        #region Commands

        RelayCommand _navigateUrlCommand;
        public RelayCommand NavigateUrlCommand
        {
            get
            {
                if (_navigateUrlCommand == null)
                {
                    _navigateUrlCommand = new RelayCommand(
                        () =>
                        {
                            //verify if it is allowed page
                            //and navigate
                            if (Uri.IsWellFormedUriString(
                                _userSuggestedSourcePage, 
                                UriKind.Absolute))
                            {
                                this.SourcePage =
                                    this.UserSuggestedSourcePage;
                            }
                        }
                        );
                }

                return _navigateUrlCommand;
            }
        }

        #endregion

    }
}

/*First application*/
//namespace UsingNonMVVMElements.ViewModel
//{
//    using GalaSoft.MvvmLight;

//    public class MainWindowViewModel : ViewModelBase
//    {
//        string _sourcePage = "http://www.google.com";
//        public string SourcePage
//        {
//            get { return _sourcePage; }
//            set
//            {
//                _sourcePage = value;
//                RaisePropertyChanged("SourcePage");
//            }
//        }
//    }
//}
